package com.example.andengineScene;

import org.andengine.entity.scene.Scene;
import org.andengine.entity.scene.background.Background;
import org.andengine.entity.sprite.Sprite;
import org.andengine.entity.text.Text;
import org.andengine.entity.text.TextOptions;
import org.andengine.input.touch.TouchEvent;
import org.andengine.opengl.font.Font;
import org.andengine.opengl.font.FontFactory;
import org.andengine.opengl.texture.region.TextureRegion;
import org.andengine.util.HorizontalAlign;
import org.andengine.util.color.Color;

import com.example.andengineConstant.GameConstant;
import com.example.andenginegame.MainActivity;

import android.graphics.Typeface;

public class MyScoreScene extends Scene  {
	
	
    private  Font myScoreTitleFont;
    private  Font todayAndAddupFont;
    private  Text title;
    
	public MyScoreScene(final MainActivity act) {
		
	         myScoreTitleFont = FontFactory.create(
	        		 act.getFontManager(),act.getTextureManager(), 
	 				280, 100, Typeface.create(Typeface.DEFAULT, Typeface.BOLD), 
	 				64, Color.WHITE.getARGBPackedInt());
	         myScoreTitleFont.load();
	         
	       
	         title = new Text(0, 0, myScoreTitleFont, "我的战绩",new TextOptions(HorizontalAlign.CENTER), act.getVertexBufferObjectManager());
	         title.setPosition(act.CAMERA_WIDTH/2-title.getWidth()/2, act.CAMERA_HEIGH/8-50);
	         float r = act.mainScene.getStyle().getMe_r();
	         float g = act.mainScene.getStyle().getMe_g();
	         float b = act.mainScene.getStyle().getMe_b();
	         
	         title.setColor(r,g,b);
	         float rt = act.mainScene.getStyle().getTarget_r();
	         float gt = act.mainScene.getStyle().getTarget_g();
	         float bt = act.mainScene.getStyle().getTarget_b();
	       
	         this.attachChild(title);
	         todayAndAddupFont = FontFactory.create(
	        		 act.getFontManager(), act.getTextureManager(), 
	        		 1000, 100, Typeface.create(Typeface.DEFAULT, Typeface.BOLD), 
	        		 38,Color.WHITE.getARGBPackedInt());
	         todayAndAddupFont.load();
	         Text gameTimes = new Text(0, 0,todayAndAddupFont, "游戏次数", act.getVertexBufferObjectManager());
	         gameTimes.setPosition(act.CAMERA_WIDTH/2-gameTimes.getWidth()/2,title.getY()+120);
	         gameTimes.setColor(r, g,b);
            
	         this.attachChild(gameTimes);
	         
	        
	         Text today = new Text(0, 0, todayAndAddupFont,"今天：", act.getVertexBufferObjectManager());
	         today.setPosition(act.CAMERA_WIDTH/2-150-today.getWidth(), gameTimes.getY()+80);
	         today.setColor( rt,gt,bt);
	         this.attachChild(today);
	         
	         Text todayNum = new Text(0, 0, todayAndAddupFont,"XXXXXXXXXSSS", act.getVertexBufferObjectManager());
	         todayNum.setPosition(today.getX()+today.getWidth()+50, gameTimes.getY()+80);
	         todayNum.setText(act.todayPlayGameNum+"");
	         this.attachChild(todayNum);
	         
	         Text addup = new Text(0, 0, todayAndAddupFont,"累计：", act.getVertexBufferObjectManager());
	         addup.setPosition(act.CAMERA_WIDTH/2+150, gameTimes.getY()+80);
	         addup.setColor(  rt,gt,bt);
	         this.attachChild(addup);
	         
	         Text addupNum = new Text(0, 0, todayAndAddupFont,"XXXXXXXXXSSS", act.getVertexBufferObjectManager());
	         addupNum.setPosition(addup.getX()+addup.getWidth()+50, gameTimes.getY()+80);
	         addupNum.setText(act.totalPlayGameNum+"");
	         this.attachChild(addupNum);
	         
	         
	         Text maxScore = new Text(0, 0, todayAndAddupFont, "最佳得分", act.getVertexBufferObjectManager());
	         maxScore.setPosition(act.CAMERA_WIDTH/2-maxScore.getWidth()/2,addup.getY()+80);
	         maxScore.setColor(r, g,b);

	         this.attachChild(maxScore);
	         Text todaymax = new Text(0, 0, todayAndAddupFont,"今天：", act.getVertexBufferObjectManager());
	         todaymax.setPosition(act.CAMERA_WIDTH/2-150-today.getWidth(), maxScore.getY()+80);
	         todaymax.setColor(  rt,gt,bt);
	         this.attachChild(todaymax);
	         
	         Text todaymaxNum = new Text(0, 0, todayAndAddupFont,"XXXXXXXXXSSS", act.getVertexBufferObjectManager());
	         todaymaxNum.setPosition(todaymax.getX()+todaymax.getWidth(), todaymax.getY());
	         todaymaxNum.setText(act.todayMaxScore+"");
	         this.attachChild(todaymaxNum);
	         
	         Text addupmax = new Text(0, 0, todayAndAddupFont,"累计：", act.getVertexBufferObjectManager());
	         addupmax.setPosition(act.CAMERA_WIDTH/2+150, maxScore.getY()+80);
	         addupmax.setColor(  rt,gt,bt);
	         this.attachChild(addupmax);
	         
	         Text addupmaxNum = new Text(0, 0, todayAndAddupFont,"XXXXXXXXXXXXS", act.getVertexBufferObjectManager());
	         addupmaxNum.setPosition(addupmax.getX()+addupmax.getWidth()+50, maxScore.getY()+80);
	         addupmaxNum.setText(act.totalMaxScore+"");
	         this.attachChild(addupmaxNum);
	         
	         
	         Text avgScore = new Text(0, 0, todayAndAddupFont, "平均得分", act.getVertexBufferObjectManager());
	         avgScore.setPosition(act.CAMERA_WIDTH/2-avgScore.getWidth()/2,todaymax.getY()+80);
	         avgScore.setColor(r, g,b);
	         this.attachChild(avgScore);
	         
	         Text todayavg = new Text(0, 0, todayAndAddupFont,"今天：", act.getVertexBufferObjectManager());
	         todayavg.setPosition(act.CAMERA_WIDTH/2-150-today.getWidth(), avgScore.getY()+80);
	         todayavg.setColor(rt,gt,bt);
	         this.attachChild(todayavg);
	         
	         Text todayavgNum = new Text(0, 0, todayAndAddupFont,"XXXXXXXXXS", act.getVertexBufferObjectManager());
	         todayavgNum.setPosition(todayavg.getX()+todayavg.getWidth()+10, avgScore.getY()+80);
	         todayavgNum.setText((act.todayScore/act.todayPlayGameNum)+"");
	         this.attachChild(todayavgNum);
	         
	         Text addupavg = new Text(0, 0, todayAndAddupFont,"累计：", act.getVertexBufferObjectManager());
	         addupavg.setPosition(act.CAMERA_WIDTH/2+150, avgScore.getY()+80);
	         addupavg.setColor(rt, gt, bt);
	         this.attachChild(addupavg);
	         
	         Text addupavgNum = new Text(0, 0, todayAndAddupFont,"XXXXXXXXXXS", act.getVertexBufferObjectManager());
	         addupavgNum.setPosition(addupavg.getX()+addupavg.getWidth()+10, avgScore.getY()+80);
	         addupavgNum.setText((act.totalScore/act.totalPlayGameNum)+"");
	         this.attachChild(addupavgNum);
	         
	         
	         
	         Text prefect = new Text(0, 0, todayAndAddupFont, "完美撞击", act.getVertexBufferObjectManager());
	         prefect.setPosition(act.CAMERA_WIDTH/2-prefect.getWidth()/2,todayavg.getY()+80);
	         prefect.setColor(r, g,b);

	         this.attachChild(prefect);
	         Text todayprefect = new Text(0, 0, todayAndAddupFont,"今天：", act.getVertexBufferObjectManager());
	         todayprefect.setPosition(act.CAMERA_WIDTH/2-150-today.getWidth(), prefect.getY()+80);
	         todayprefect.setColor(rt,gt,bt);
	         this.attachChild(todayprefect);
	         
	         Text todayprefectNum = new Text(0, 0, todayAndAddupFont,"XXXXXXXXXXXX", act.getVertexBufferObjectManager());
	         todayprefectNum.setPosition(todayprefect.getX()+todayprefect.getWidth()+10, prefect.getY()+80);
	         todayprefectNum.setText(act.todayPrefectNum+"");
	         this.attachChild(todayprefectNum);
	         
	         Text addupprefect = new Text(0, 0, todayAndAddupFont,"累计：", act.getVertexBufferObjectManager());
	         addupprefect.setPosition(act.CAMERA_WIDTH/2+150, prefect.getY()+80);
	         addupprefect.setColor(rt,gt,bt);
	         this.attachChild(addupprefect);
	         
	         Text addupprefectNum = new Text(0, 0, todayAndAddupFont,"XXXXXXXXXXXX", act.getVertexBufferObjectManager());
	         addupprefectNum.setPosition(addupprefect.getX()+addupprefect.getWidth()+10, prefect.getY()+80);
	         addupprefectNum.setText(act.totalPrefectNum+"");
	         this.attachChild(addupprefectNum);
	         
	         Text prefectavg = new Text(0, 0, todayAndAddupFont, "完美撞击/每局", act.getVertexBufferObjectManager());
	         prefectavg.setPosition(act.CAMERA_WIDTH/2-prefectavg.getWidth()/2,todayprefect.getY()+80);
	         prefectavg.setColor(r, g,b);
	         this.attachChild(prefectavg);
	         
	         Text todayprefectavg = new Text(0, 0, todayAndAddupFont,"今天：", act.getVertexBufferObjectManager());
	         todayprefectavg.setPosition(act.CAMERA_WIDTH/2-150-today.getWidth(), prefectavg.getY()+80);
	         todayprefectavg.setColor(rt,gt,bt);
	         this.attachChild(todayprefectavg);
	         
	         Text todayprefectavgNum = new Text(0, 0, todayAndAddupFont,"XXXXXXXXXXXXXX", act.getVertexBufferObjectManager());
	         todayprefectavgNum.setPosition(todayprefectavg.getX()+todayprefectavg.getWidth()+10, prefectavg.getY()+80);
	         todayprefectavgNum.setText((act.todayPrefectNum/act.todayPlayGameNum)+"");
	         this.attachChild(todayprefectavgNum);
	         
	         
	         Text addupprefectavg = new Text(0, 0, todayAndAddupFont,"累计：", act.getVertexBufferObjectManager());
	         addupprefectavg.setPosition(act.CAMERA_WIDTH/2+150, prefectavg.getY()+80);
	         addupprefectavg.setColor(rt, gt, bt);
	         this.attachChild(addupprefectavg);
	         
	         Text addupprefectavgNum = new Text(0, 0, todayAndAddupFont,"XXXXXXXXXXXXXX", act.getVertexBufferObjectManager());
	         addupprefectavgNum.setPosition(addupprefectavg.getX()+addupprefectavg.getWidth()+10, prefectavg.getY()+80);
	         addupprefectavgNum.setText((act.totalPrefectNum/act.totalPlayGameNum)+"");
	         this.attachChild(addupprefectavgNum);
	         
	         Text back = new Text(0, 0,todayAndAddupFont , "返回", act.getVertexBufferObjectManager()){
				 public boolean onAreaTouched(TouchEvent touchEvent, float X, float Y)

			        {
			            if (touchEvent.isActionUp())

			            {

			            	if(act.mEng.isRunning()) {
			            		
			            		
			            		
			        			
			        			 act.mEng.setScene(act.mainScene);
			    			} else {
			    			
			    				act.mEng.start();
			    			}
			    			return true;

			            }

			            return true;

			        }
				};
			 TextureRegion backTexture = act.ur3.get(4);
			 final float missionX = (act.CAMERA_WIDTH-backTexture.getWidth())/2;
			 Sprite backSprite = new Sprite(missionX,350,backTexture,act.getVertexBufferObjectManager());
			 backSprite.setPosition(act.CAMERA_WIDTH/2-backSprite.getWidth()/2, act.CAMERA_HEIGH-backSprite.getHeight()-50);
			 backSprite.setColor(GameConstant.UNDER_COLOR_R,GameConstant.UNDER_COLOR_G,GameConstant.UNDER_COLOR_B);
             this.attachChild(backSprite);
          	 back.setPosition(act.CAMERA_WIDTH/2-backSprite.getWidth()/2+(backSprite.getWidth()-back.getWidth())/2, act.CAMERA_HEIGH-backSprite.getHeight()-50+(backSprite.getHeight()-back.getHeight())/2);
             back.setColor(rt,gt,bt);
          	 this.attachChild(back);
	         this.registerTouchArea(back);
             
	         this.setBackground(new Background(act.mainScene.style.getBg_r(),act.mainScene.style.getBg_g(),act.mainScene.style.getBg_b()));
	}

}
